********* TABLE 3 *********

clear all
set more off 
capture log close

* main path 
global path "~/Dropbox/Paraguay/1_data/7_replication_dataverse"
capture cd "$path"	

*tables = analysis tables
global tables "$path/tables"

* Load and prepare data
use "$path/data/anr.dta", clear
xtset district_code periods
generate autocracy = (periods<=6)

eststo clear

* Loop over centrality measures
local measures "lambda degree betweenness"
local labels `" "Eigenvalue" "Degree" "Betweenness" "'

forvalues i = 1/3 {
    local measure : word `i' of `measures'
    local label : word `i' of `labels'
    
    reghdfe l_anr i.autocracy##c.`measure'_z, absorb(periods district_code i.periods#i.depa) cluster(district_code)
    
    * Store mean of dependent variable
    summ l_anr if e(sample)==1 
    estadd local meanDep = trim("`: display %12.4fc `r(mean)''")
    
    eststo model`i'
}

* Create table
capture cd "$tables"
esttab model* using "table3.tex", replace nonumber label style(tex) ///
    cells(b(star fmt(%12.4fc)) se(par fmt(%12.4fc))) ///
    stats(meanDep N r2, fmt(%12.4fc %12.0fc %12.4fc) ///
        label("Outcome mean" "Observations" "\$R^2\$")) ///
    keep(1.autocracy#c.lambda_z 1.autocracy#c.degree_z 1.autocracy#c.betweenness_z) ///    
    order(1.autocracy 1.autocracy#c.lambda_z 1.autocracy#c.degree_z 1.autocracy#c.betweenness_z) ///
    varlabels(1.autocracy "Autocracy" ///
             1.autocracy#c.lambda_z "Autocracy \$\times\$ Eigenvalue" ///
             1.autocracy#c.degree_z "Autocracy \$\times\$ Degree" ///
             1.autocracy#c.betweenness_z "Autocracy \$\times\$ Betweenness") ///    
    collabels(none) eqlabels(none) starlevels(* 0.1 ** 0.05 *** 0.01) ///
    prehead("\begin{tabular}{l*{@M}{c}} \hline" ///
           "&  \multicolumn{3}{c}{Colorado Party Affiliations (log)}    \\" ///
           "& (1) & (2) & (3)     \\") ///
    posthead(\hline) mlabels(none) ///
    prefoot() postfoot(\hline \end{tabular})
